package org.lanqiao.tjut.Controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.Bean.CourseBean;
import org.lanqiao.tjut.Bean.ScoreBean;
import org.lanqiao.tjut.MyUtils.MyUtils;
import org.lanqiao.tjut.Service.ServiceFactory;

public class TeaCourseInfoModifyServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 选课 & 退课
		/*
		 * 从前台传回教师信息，通过教师id查找相关课程信息， 如果没有课程信息，则添加课程信息
		 */
		// 准备用户进行修改的数据
		String strOperationType = request.getParameter("opt");
		int iOpt = MyUtils.obj2Int(strOperationType);
		// 结果跳转页面
		String strJumpPage = "";
		// 后台uid代指couid
		if(iOpt==1){
			//查询选课学生
			String couid = request.getParameter("uid");
			List<ScoreBean> lstSco = ServiceFactory.getStuInfoManagerServiceInstance().getStuInfoByCouid(couid);
			// 将数据缓存在session对象中
			request.setAttribute("lstSco", lstSco);
			// 跳转到修改结果页
			strJumpPage = "logined/gradeAndCourseManager/StuScoreInput.jsp";
		}

		if (iOpt == 2) {
			// 选课
			// 获取教师id
			String teaid = "00" + request.getParameter("uid");
			// 根据教师id查询课程信息，如果没有已选课程，则默认显示所有课程
			CourseBean couB = ServiceFactory.getTeacherInfoManagerServiceInstance().getCourseInfoByTeaid(teaid);
			if (couB != null) {
				// 将数据缓存在session对象中
				request.setAttribute("courseB", couB);
				// 跳转到修改结果页
				strJumpPage = "logined/gradeAndCourseManager/CourseAdd.jsp";
			} else {
				// 否则遍历所有课程信息
				List<CourseBean> lstCou = ServiceFactory.getTeacherInfoManagerServiceInstance().getAllTCourseInfo();
				// 将数据缓存在session对象中
				request.setAttribute("lstCou", lstCou);
				// 跳转到修改结果页
				strJumpPage = "logined/gradeAndCourseManager/teaCourseDetail.jsp";
			}
		}

		// 跳转到修改页面
		request.getRequestDispatcher(strJumpPage).forward(request, response);

	}

}
